package modelo.reglas.composite.inner;

import java.lang.reflect.InvocationTargetException;

import modelo.reglas.ISpecification;
import modelo.reglas.Specificable;

public class FieldValueSpecification<T extends Specificable> extends
		ISpecification<T> {

	private String field;
	private Object value;
	private Class objectType;

	public FieldValueSpecification(String field, Object value,
			Class objectType) {
		this.field = field;
		this.value = value;
		this.objectType = objectType;
	}

	@Override
	public Boolean isSatisfiedBy(T specificable) {
		try {
			return objectType.cast(specificable).getClass().getMethod("get" + field).invoke(specificable)
					.equals(value);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

}
